<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="/struts-tags" prefix="s" %>
<%@ taglib uri="/sinopac-fn" prefix="fn" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="${fn:url('/form/CSS/tabs.css')}">
<link rel="stylesheet" href="${fn:url('/form/CSS/jquery-ui-1.10.1.css')}">
<script type="text/javascript" src="${fn:url('/js/jQuery/jquery-1.8.2.min.js')}"></script>
<script type="text/javascript" src="${fn:url('/js/jQuery/jquery_DOMWindow.js')}"></script>
<script type="text/javascript" src="${fn:url('/js/jQuery/jquery-ui-autocomplete.min.js')}"></script>
<script type="text/javascript" src="${fn:url('/js/tools/formUtil.js')}"></script>
<script>
	function getCustomer_id(custId){
		var form = $('#form1');
		form.prop('action', '${fn:url('/Index/chkCustId.action')}');
		form.append('<input type="hidden" name="function_num" value="2" />');
		form.append('<input type="hidden" name="custId" value="'+custId+'" />');
		form.submit();
	}
	$(document).ready(function(){
		$("input[name=btnUpdate]").click(function(){
			var url = "${fn:url('/CustomerApply/updateData')}";
			var token_esn = $("#token_esn").val();
			var customer_contact = $("input[name=customer_contact]").val();
			var customer_phone = $("input[name=customer_phone]").val();
			var customer_address = $('#customer_address').val();
			var mailarea = $("input[name=mailarea]").val();
    		var mailbarcode = $("input[name=mailbarcode]").val();
			$.ajax({  
                type: "post",  
                url: url,  
                dataType: "json",  
                data: {"token_esn":token_esn,
                	   "customer_contact":customer_contact,
                	   "customer_phone":customer_phone,
                	   "customer_address":customer_address,
                	   "mailarea":mailarea,
                	   "mailbarcode":mailbarcode},  
                beforeSend: function(XMLHttpRequest){  
                    //ShowLoading();  
                    $("#str").val("正在處理中...");  
                },  
                success: function(data){  
                	if(data != ""){
	                    alert("此Token esn載具\t"+data); 
	                    $("#token_esn").select();
                	}else{
                		alert("客戶資料更新完成！");
                		$("input[name=token_esn]").val(token_esn);
                	}
                },
                error: function(){ alert("客戶資料更新失敗！ 請檢查客戶資料內容是否正確"); } 
            }); 
		});
		
		$("#token_esn").autocomplete({
    		delay: 1000,
    		minLength: 1,
            source: function(request, response) {
                $.ajax({
                    url: "${fn:url('/ccroger/queryToken')}",
                    dataType: "json",
                    type: "post",
                    data: {"search":request.term},
                    success: function(data) {
				    	var dataset = [];
                    	var jo = eval("("+data+")");   
                        $(jo).each(function(i,item){ 
                        	dataset.push(item.tokenEsn);
                        });  
                        response(dataset);
                        $('.ui-menu-item').css("font-size","12px");
                        $('.ui-menu-item').css("font-weight","normal");
                    },
                });
            }
        });
		
		var token = $("input[name=token_esn]").val();
		$("#token_esn").val(token);
	});

	var winObj1; 
	function abgne1(url){ 
	       winObj1 = window.open(url);
	       winObj1.document.getElementById("path").value = "C:\\PDF\\Test.pdf"; 
	} 
</script>
<title>申請配發確認</title>
</head>
<body>
	<%@ include file="/form/include/title.jsp" %>
	<s:form id="form1">
		<input type="hidden" name="custId"/>
		<table class="table-style" align="center">
		<tr>
			<th>客戶ID</th>
			<th>客戶名稱</th>
			<th>AO Code</th>
			<th>集團戶</th>
			<th>TOKEN ESN</th>
			<th>OTP 狀態</th>
			<th>最近異動經辦</th>
		</tr>
		<s:iterator value="customerList" status="c" var="cus">
			<tr>
				<td><s:property value="customer_id"/></td>
				<td><s:property value="customer_name"/></td>
				<td><s:property value="ao_code"/></td>
				<s:if test='%{is_group.equals("0")}'>
					<td>否</td>
				</s:if>
				<s:else>
					<td>是</td>
				</s:else>
				<td><input type="text" id="token_esn" value="${ token_esn }" size="17" maxlength="16"></td>
				<td><s:property value="otp_status_msg"/></td>
				<td><s:property value="#session.userName"/></td>
			</tr>
		</s:iterator>
		</table>
		<table class="table-style" align="center">
			<tr height="20"/>
			<tr>
				<th>收件人</th>
				<th>聯絡人電話</th>
				<th>聯絡地址</th>
			</tr>
			<s:iterator value="customerList" var="c">
				<tr>
					<td><input type="text" size="25" name="customer_contact" value="${ customer_contact }"/></td>
					<td><input type="text" size="25" name="customer_phone" value="${ customer_phone }"/></td>
					<td><textarea cols="60" rows="2" id="customer_address" name="customer_address">${ customer_address }</textarea></td>
				</tr>
			</s:iterator>
			<tr>
				<th>郵件區域</th>
				<th>郵件條碼</th>
			</tr>
			<s:iterator value="customerList" var="c">
				<tr>
					<td><input type="text" size="25" name="mailarea" value="${ mailarea }"/></td>
					<td><input type="text" size="25" name="mailbarcode" value="${ mailbarcode }"/></td>
				</tr>
			</s:iterator>
		</table>
			<table align="center">
				<tr align="center">
					<td style="font-size: 20px">集團戶關聯客戶ID:</td>
				</tr>
			</table>
			<table class="table-style" align="center">
				<tr>
					<th>客戶ID</th>
					<th>客戶名稱</th>
					<th>AO Code</th>
				</tr>
				<s:if test="GroupList.size()>0">
					<s:iterator value="GroupList" var="group">
						<tr>
							<td><a onclick="getCustomer_id('${group.customer_id}')" href="#"><s:property value="customer_id"/></a></td>
							<td><s:property value="customer_name"/></td>
							<td><s:property value="ao_code"/></td>
						</tr>
					</s:iterator>
				</s:if>
			</table>
		<table align="center">
			<tr>
				<td>
					<s:submit theme="simple" value="確認及列印領據" action="printRoport" ></s:submit>
					<input type="button" name="btnUpdate" value="更新">
					<s:submit theme="simple" value="取消" action="index"></s:submit>
					<input type="hidden" name="token_esn" value="<s:property value="token_esn"/>" />
				</td>
			</tr>
		</table>
	</s:form>
</body>
</html>